﻿@model Kooboo.Web.Mvc.Grid2.GridModel
@helper RenderHeader()
{
    <thead>
        <tr>
            @if (Model.Checkable)
            {
                <th class="checkbox">
                    <input type="checkbox" class="select-all" />
                </th>
            }
            @foreach (var column in Model.Columns)
            {
                <th @column.RenderHeaderContainerAtts(ViewContext)>
                    @column.RenderHeader(ViewContext)
                </th>
            }
        </tr>
    </thead>
}
<div class="common-table fixed">
    <div class="thead">
        <table>
            @RenderHeader()
        </table>
    </div>
    <div class="tbody">
        <table>
            @RenderHeader()
            <tbody>
                @{
                    var categoryList = ViewData["CategoryList"] == null ? new string[0] : ((IEnumerable<string>)ViewData["CategoryList"]).ToArray();
                    var items = Model.GetItems().ToArray();
                }
                @if (categoryList.Length == 0 && items.Length == 0)
                { 
                    <tr class="empty">
                        <td colspan="100">
                            @(string.IsNullOrEmpty(Model.GridAttribute.EmptyText) ? ("Empty".Localize()) : Model.GridAttribute.EmptyText)
                        </td>
                    </tr>
                }
                else
                {
                    if (categoryList != null)
                    {
                        foreach (var c in categoryList)
                        {
                            if (!string.IsNullOrEmpty(c))
                            { 
                    <tr>
                        <td class="checkbox">
                            <input type="checkbox" value="@c" class="select folder" />
                        </td>
                        <td colspan="5">
                            @Html.ActionLink(c, "Index", ViewContext.RequestContext.AllRouteValues().Merge("Category", c), new RouteValueDictionary(new { @class = "f-icon folder" }))
                        </td>
                    </tr>
                            }
                        }
                    }
                    foreach (var item in items)
                    {
                    <tr @item.RenderItemContainerAtts()>
                        @if (Model.Checkable)
                        {
                            <td class="checkbox">
                                <input type="checkbox"  class="select doc" value="@item.IdPropertyValue" data-id-property="@Model.IdPorperty"
                                 @(item.IsCheckable == true ? "" : "disabled")/>
                            </td>
                        }
                        @foreach (var itemValue in item.GetItemColumns())
                        {
                            <td @itemValue.RenderItemColumnContainerAtts(ViewContext)>
                                @itemValue.RenderItemColumn(ViewContext)
                            </td>
                        }
                    </tr>            
                    }
                }
            </tbody>
        </table>
    </div>
</div>
